﻿using System;
namespace TL2
{
    public class CleanHtmlTags
    {
        /**
    * Cleans txt file from html tags
    * @param text
    *   text to be cleaned
    * @return
    *   cleaned text
    */
        public static string Clean(string text)
        {
            char[] array = null;
            int arrayIndex = 0;
            try
            {
                array = new char[text.Length];
                
                bool inside = false;

                for (int i = 0; i < text.Length; i++)
                {
                    char let = text[i];
                    if (let == '<')
                    {
                        inside = true;
                        continue;
                    }
                    if (let == '>')
                    {
                        inside = false;
                        continue;
                    }
                    if (!inside)
                    {
                        array[arrayIndex] = let;
                        arrayIndex++;
                    }
                }
            }
            catch (NullReferenceException)
            {
                Messages.Messanger("Το αρχείο δεν βρέθηκε");
                return null;
            }
            return new string(array, 0, arrayIndex);
        }
    }
}
